<?include_once('conn.php');?>
<?include_once('inc_head.php');?>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<?
$act=$_GET['act'];
$series=$_GET['sid'];
$series=isset($series)?$series:0;
$_TABLE = TABLE_C."vote_question"; #要操作的表
$path='../uploads/content/';
#/////////////////////////首页显示/////////////////////
if($act=='showindex')
{	
	$id=addslashes($_GET['id']);
	$cmd="update $_TABLE set isindex=1  where id=".$id;
	if(mysql_query($cmd) or die(mysql_error())){
	gourl('已设置显示在首页！',$cururl);	
	}
	exit;
}
#/////////////////////////首页不显示/////////////////////
if($act=='hideindex')
{	
	$id=addslashes($_GET['id']);
	$cmd="update $_TABLE set isindex=0  where id=".$id;
	if(mysql_query($cmd) or die(mysql_error())){
	gourl('已隐藏！',$cururl);	
	}
	exit;
}
#/////////////////////////修改/////////////////////
if($act=='editok')
{	$id=$_POST['id'];
	$title=rq('title');
	$videourl=stripslashes($_POST['videourl']);
	$series=intval($_POST['smallname']);
	$message=$_POST['message2'];
	$cmd="update $_TABLE set title='".$title."',series=".$series.",message='".$message."',videofile='$videofile' where id=".$id;
	if(mysql_query($cmd) or die(mysql_error())){
	gourl('修改成功！',$cururl);	
	}
	exit;
}
#/////////////////////////删除/////////////////////
if($act=='del') {	
	$id=addslashes($_GET['id']); 
	//从数据数据库
	$cmd="delete from $_TABLE where id=".$id;
	if(mysql_query($cmd) or die(mysql_error())){
	gourl('删除成功！',$cururl);	
	}
	exit;
}

////////////////////////////////////  复选框批量操作   ///////////////////////////////////////////////
if($act=="doall"){
	 $doact=$_POST['doact'];#子动作
	 $idarr=$_POST['checkbox'];
	  if($_POST['checkbox']==""){gourl("没有选择序列！",$cururl);exit;}#是否有选择
	 $allID=implode(",",$_POST['checkbox']);#处理ID
	 $orderVal=intval($_POST['orderVal']);#排序的值 
	 switch($doact){
		 #更改排序
		 case "orderby":
		 if($orderVal==0){gourl("排序数字无效",$cururl);}
		 $cmd="update $_TABLE set orderby=$orderVal where id in($allID)";
		 if(mysql_query($cmd) or die(mysql_error())){
			gourl("已经将ID为".$allID."的记录批量排序。",$cururl);
		 }
		 
		 break;
		 
		 #移动
		 case "moveto":
		 $tosid=intval($_POST['moveseries']);
		 $cmd="update $_TABLE set series=$tosid where id in($allID)";
		 if(mysql_query($cmd) or die(mysql_error())){
			gourl("已经将ID为".$allID."的记录批量移动",$cururl);
		 }
		 break;
		 
		 #批量删除
		 case "del":
			 for($i=0;$i<count($idarr);$i++){
				$id=$idarr[$i];
				echo "<br>处理ID为 $id 的记录:";
				//从数据数据库
				$cmd="delete from $_TABLE where id=".$id;
				if(mysql_query($cmd) or die(mysql_error())){
					echo "<div class=tipsok>成功从数据库删除</div>";
				}
				#删除结束
			 }
			 echo " 点击 <a href=".$_SESSION['lastUrl'].">这里</a> 返回";
		 break;
	 }
	 exit;
}
?>
<body>
<?local("问题管理");?>
<div id="intro">
<!-------------------------------------默认状态------------------------------------->
<table width="100%" border="0"  cellpadding="2" cellspacing="0">
  <tr> 
      <td width="50%"> 
			<?
			echo '<select name="smallname" id="smallname"  onchange="selectSeries(this.value)">';
			echo '<option  value="0" style="background:yellow;">全部</option>';
			$cmd1="select * from ".TABLE_C."vote_series where forid=0 order by id";
			$rs1=mysql_query($cmd1) or die(mysql_error());
			while($row1=mysql_fetch_assoc($rs1)){
				echo '<optgroup  label='.$row1[name].'>';
				////////////////2级循环////////////////////////
				$cmd2="select * from ".TABLE_C."vote_series where forid={$row1[id]} order by id";
				$rs2=mysql_query($cmd2) or die(mysql_error());
				while($row2=mysql_fetch_assoc($rs2)){
					if($row2['id']==$_GET['sid']){
						echo '<option selected value='.$row2[id].'>&nbsp;&nbsp;|—'.$row2[name].'</option>';
					}else{
						echo '<option value='.$row2[id].'>&nbsp;&nbsp;|—'.$row2[name].'</option>';
					}
				}
				mysql_free_result($rs2);
				echo '</optgroup>';
			}
			mysql_free_result($rs1);
			echo '</select>';
			?>
			
		    <?
			#显示排序
			echo " <a href='?sid=$series&okey=id asc' class='btn btn-md btn-default'>ID▲</a> ";
			echo " <a href='?sid=$series&okey=id desc' class='btn btn-md btn-default'>ID▼</a>";
			echo " <a href='?sid=$series&okey=orderby desc' class='btn btn-md btn-default'>排▲</a>";
			echo " <a href='?sid=$series&okey=orderby asc' class='btn btn-md btn-default'>排▼</a>";
		    ?>
       </td>
			
      <td width="50%" align=right> 
        <?	
        	$okey=get2('okey');
		$page=intval($_GET['page']);
		if($page==0){$page=1;}
		$pagesize=$news_pagesize;
		$rsStar=$page*$pagesize-$pagesize;
		//判断条件
		if($series){
			$condition="where l.series = $series";
		}else{
			$condition="";
		}
		//总数
		$cmd="select  id from $_TABLE l ".$condition;
		$rs=mysql_query($cmd) or die(mysql_error());
		$rstotal=mysql_num_rows($rs);
		
		//排序整理
		$orderTxt="order by l.$okey";
		if($okey==''){
			$orderTxt='order by id desc';
		}
		
		$cmd="select l.*,x.ntitle from $_TABLE l 
		left join (select *,name ntitle from ".TABLE_C."vote_series) x on x.id=l.series ".$condition." ".$orderTxt." LIMIT $rsStar,$pagesize";
		$rs=mysql_query($cmd) or die(mysql_error());	
		$pagetotal=ceil($rstotal/$pagesize);
		echo "<div>当前分类记录数共【".$rstotal."】条,每页显示【".$pagesize."】条 ,页码：$page/$pagetotal</div>";
		 ?>
	  </td>
          </tr>
        </table>
	<!--主内容表格-->
<form name="form_all" method=post action="?act=doall" style="margin:0px">
  <table class="table table-hover table-bordered table-striped" width="100%" border="0"  cellpadding="0" cellspacing="0" >
    <tr> 
      <th width="30"  >&nbsp;</th>
      <th width="70"  >ID</th>
      <th width="70"  >排</th>
	  <th width="70"  >显</th>
      <th width="" >标题 </th>
      <th width="150" >分类</th>
      <th width="150"  >操作</th>
    </tr>
    <?
   	showemptyrs($rs);
	while($rowL=mysql_fetch_assoc($rs)){
	  $id=$rowL['id'];
	  $title=$rowL['title'];
	  $series=$rowL['series'];
	  $si=$rowL['isindex'];
  ?>
    <tr  class="mytr" > 
      <td align="center"  > <input type=checkbox value="<? echo $id ?>" name="checkbox[]"></td>
      <td align="center" ><? echo $id ?></td>
      <td align="center"  ><span class="ajaxspan" onclick="ajaxhtml(this,'content_order',<?echo $rowL['id'];?>);"><? echo $rowL['orderby'];?></span></td>
	  <td align="center"  >
        <? if($si==0){
			echo "<a href=?act=showindex&id=".$id." class=''><i class=\"fa fa-lg fa-remove c-red\"></i></a>";
		}else{
			echo "<a href=?act=hideindex&id=".$id."  class=' '><i class=\"fa fa-lg fa-check c-green\"></i></a>";
		} 
		?>
      </td>
      <td align=""><? echo $title=$rowL['title'];?></td>
      <td align=""  ><? echo $rowL['ntitle'];?></td>
	  
      <td align="center" > 
		<a href="admin_vote_edit.php?id=<?echo $id?>" class="btn btn-xs btn-info" rel="floatEdit" target="_blank">编辑</a> 
 		<a  href="javascript:if(confirm('确定吗')){window.location='?act=del&id=<?echo $id?>&vfile=<? echo $rowL['videofile'];?>&imgf=<?echo $rowL['imagefile'];?>'}" class="btn btn-xs btn-danger">删除</a> 
       </td>
    </tr>
    <?}?>
  </table>

  <!--下面的控制表格-->
  <table width="100%" border="0"  cellpadding="5" cellspacing="0">
	<tr>
	<td width="50%" >
			<label><input name="selectall" type="checkbox" id="selectall" onclick="select_all()"/>全选 </label> 
			<input type="hidden" name="doact" id="doact" value="none"/>
			<button  type="button" class="btn btn-md btn-default" value="删除" onClick="doall('del');">删除 </button>
			<input name="orderVal" class="form-control"  value="1" size=2 maxlength=3 class="">
			<button type="button" class="btn btn-md btn-default"  onClick="doall('orderby');">排序</button>
			
			
			<?
			echo '<select name="moveseries" id="moveseries"  onchange="doall(\'moveto\')">';
			echo '<option  value="0" >移动到...</option>';
			$cmd1="select * from ".TABLE_C."vote_series where forid=0 order by id";
			$rs1=mysql_query($cmd1) or die(mysql_error());
			while($row1=mysql_fetch_assoc($rs1)){
				echo '<optgroup  label='.$row1[name].'>';
				////////////////2级循环////////////////////////
				$cmd2="select * from ".TABLE_C."vote_series where forid={$row1[id]} order by id";
				$rs2=mysql_query($cmd2) or die(mysql_error());
				while($row2=mysql_fetch_assoc($rs2)){
					if($row2['id']==$_GET['sid']){
						echo '<option selected value='.$row2[id].'>&nbsp;&nbsp;|—'.$row2[name].'</option>';
					}else{
						echo '<option value='.$row2[id].'>&nbsp;&nbsp;|—'.$row2[name].'</option>';
					}
				}
				mysql_free_result($rs2);
				echo '</optgroup>';
			}
			mysql_free_result($rs1);
			echo '</select>';
			?>
	</td>
	<td width="" align=right><? echo turnpage2($pagesize,$rstotal);?></td>
	</tr>
  </table>
  </form>
  
</div>
<?include('inc_foot.php');?>
</body>
</html>